<template>
	<div>
		<el-tabs v-model="activeName" @tab-click="handleClick">
			<el-tab-pane label="采购在途" name="first">
				<el-row :gutter="24">
					<el-col :span="24">
						<el-row :gutter="24">
							<el-col :span="1" style="">
								<p class="queryLabel">单位:</p>
							</el-col>
							<el-col :span="3">
								<el-input placeholder="请选择单位" size="small" icon="more" v-model="carSelectCompany" :on-icon-click="openDeptTree">
								</el-input>
							</el-col>
							<el-col :span="1" style="text-align: left; ">
								<p class="queryLabel">采购日期:</p>
							</el-col>
							<el-col :span="3" style="margin-left: 10px;">
								<el-date-picker v-model="data.firstStart" size="small" style="width:100%;" type="date" clearable placeholder="采购日期">
								</el-date-picker>
							</el-col>
							<el-col :span="1" style="text-align: left;">
								<p class="queryLabel">至:</p>
							</el-col>
							<el-col :span="3">
								<el-date-picker v-model="data.firstStarts" size="small" style="width:100%;" type="date" clearable placeholder="采购日期">
								</el-date-picker>
							</el-col>
							<el-col :span="1" style="text-align: left;">
								<p class="queryLabel">VIN:</p>
							</el-col>
							<el-col :span="3">
								<el-input placeholder="请输入VIN" size="small" v-model="carSelect.vin">
								</el-input>
							</el-col>
							<el-col :span="7" style="text-align: right;">
								<el-button type="primary" size="small" @click="query">查询</el-button>
								<el-button type="primary" size="small" @click="del">删除</el-button>
								<el-button type="primary" size="small" @click="add">新增</el-button>
								<el-button type="primary" size="small" @click="refreshP">刷新暂估价</el-button>
								<el-button type="primary" size="small" @click="editPrice">维护暂估价</el-button>

								<!--<el-button type="primary" size="small" @click="edit">修改</el-button>-->
							</el-col>
						</el-row>
						<el-row :gutter="24">
							<el-col :span="1" style="">
								<p class="queryLabel">车系:</p>
							</el-col>
							<el-col :span="3">
								<el-input placeholder="请选择车系" size="small" icon="search" v-model="carModelCode" :on-icon-click="handleIconClick">
								</el-input>
							</el-col>
							<el-col :span="1" style="text-align: left;">
								<p class="queryLabel">车辆型号:</p>
							</el-col>
							<el-col :span="3">
								<el-select size="small" style="width: 100%; margin-left: 10px;" v-model="carSelect.carModelCode" placeholder="请选择配置" clearable @change="changeModel">
									<el-option v-for="item in modelCombo" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-col>
							<el-col :span="1" style="text-align: left;">
								<p class="queryLabel">车辆配置:</p>
							</el-col>
							<el-col :span="3" style="text-align: left; margin-left: 5px;">
								<el-select size="small" style="width: 100%;" v-model="carSelect.carConfigureCode" placeholder="请选择配置" clearable>
									<el-option v-for="item in configCombo" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-col>
							<el-col :span="11" style="text-align: right; ">

								<el-button type="primary" size="small" @click="refreshC">刷新车型</el-button>
								<el-button type="primary" size="small" @click="refreshF">刷新配置</el-button>
								<el-button type="primary" size="small" @click="refreshW">刷新外观内饰</el-button>
								<el-button type="primary" size="small" @click="clean">清空查询条件</el-button>&nbsp;
							</el-col>
						</el-row>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24">
						<el-table :data="tableData.dataList" border @selection-change="handleSelectionChange" :row-class-name="tableRowClassNames">
							<el-table-column type="selection" width="55" label="选择">
							</el-table-column>
							<el-table-column prop="vin" label="VIN" width="180">
							</el-table-column>
							<el-table-column prop="estimatePrice" label="暂估价格" width="100">
							</el-table-column>
							<el-table-column prop="purchaseDate1" label="采购日期" width="110">
							</el-table-column>
							<el-table-column prop="purchaseNum" label="采购单号" width="140">
							</el-table-column>
							<el-table-column prop="carSeries" label="车系名称" width="150">
							</el-table-column>
							<el-table-column prop="carModelCode" label="车型代码" width="100">
							</el-table-column>
							<el-table-column prop="modelName" label="车型名称" width="150">
							</el-table-column>
							<el-table-column prop="configureCode" label="配置代码" width="100">
							</el-table-column>
							<el-table-column prop="configureName" label="配置名称" width="150">
							</el-table-column>
							<el-table-column prop="carModelYear" label="车型年" width="100">
							</el-table-column>
							<el-table-column prop="appearanceCode" label="外观代码" width="100">
							</el-table-column>
							<el-table-column prop="appearanceName" label="外观颜色" width="100">
							</el-table-column>
							<el-table-column prop="trimCode" label="内饰代码" width="100">
							</el-table-column>
							<el-table-column prop="trimName" label="内饰名称" width="100">
							</el-table-column>
							<el-table-column prop="chooseCode" label="加装代码" width="100">
							</el-table-column>
							<el-table-column prop="chooseName" label="加装名称" width="100">
							</el-table-column>
							<el-table-column prop="distributionDate" label="配货日期" width="120">
							</el-table-column>
							<el-table-column prop="sendDate" label="发货日期" width="120">
							</el-table-column>
							<el-table-column prop="oldNum" label="提单号" width="100">
							</el-table-column>
							<el-table-column prop="distributionStatus" label="配货状态" width="100">
								<!--addNoStoreFormData.provideCompanyName-->
							</el-table-column>
							<el-table-column prop="provideCompanyName" label="购货单位" width="100">
							</el-table-column>
						</el-table>
						<el-pagination small @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="CurentPage" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="tableData.total">
						</el-pagination>
					</el-col>
				</el-row>
			</el-tab-pane>
			<el-tab-pane label="调拨在途" name="second">
				<el-row :gutter="24">
					<el-col :span="24">
						<el-row :gutter="24">
							<el-col :span="1" style="">
								<p class="queryLabel">单位:</p>
							</el-col>
							<el-col :span="3">
								<el-input placeholder="请选择单位" size="small" icon="more" v-model="carSelectCompany" :on-icon-click="openDeptTree">
								</el-input>
							</el-col>
							<el-col :span="1" style="text-align: left; ">
								<p class="queryLabel">采购日期:</p>
							</el-col>
							<el-col :span="3" style="margin-left: 10px;">
								<el-date-picker v-model="data.firstStart" size="small" style="width:100%;" type="date" clearable placeholder="采购日期">
								</el-date-picker>
							</el-col>
							<el-col :span="1" style="">
								<p class="queryLabel">至:</p>
							</el-col>
							<el-col :span="3">
								<el-date-picker v-model="data.firstStarts" size="small" style="width:100%;" type="date" clearable placeholder="采购日期">
								</el-date-picker>
							</el-col>
							<el-col :span="1" style="text-align: left;">
								<p class="queryLabel">VIN:</p>
							</el-col>
							<el-col :span="3">
								<el-input placeholder="请输入VIN" size="small" v-model="carSelect.vin">
								</el-input>
							</el-col>
						</el-row>
						<el-row :gutter="24">
							<el-col :span="1" style="">
								<p class="queryLabel">车系:</p>
							</el-col>
							<el-col :span="3">
								<el-input placeholder="请选择车系" size="small" icon="search" v-model="carModelCode" :on-icon-click="handleIconClick">
								</el-input>
							</el-col>
							<el-col :span="1" style="text-align: left; ">
								<p class="queryLabel">车辆型号:</p>
							</el-col>
							<el-col :span="3">
								<el-select size="small" style="width: 100%; margin-left: 10px;" v-model="carSelect.carModelCode" placeholder="请选择配置" clearable @change="changeModel">
									<el-option v-for="item in modelCombo" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-col>
							<el-col :span="1" style="">
								<p class="queryLabel">车辆配置:</p>
							</el-col>
							<el-col :span="3" style="text-align: left; margin-left: 5px;">
								<el-select size="small" style="width: 100%;" v-model="carSelect.carConfigureCode" placeholder="请选择配置" clearable>
									<el-option v-for="item in configCombo" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-col>
							<el-col :span="11" style="text-align: right;">
								<el-button type="primary" size="small" @click="query">查询</el-button>
								<el-button type="primary" size="small" @click="clean">清空查询条件</el-button>
							</el-col>
						</el-row>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24">
						<el-table :data="tableData.dataList" border @selection-change="handleSelectionChange" :row-class-name="tableRowClassNames">
							<el-table-column type="selection" width="55" label="选择">
							</el-table-column>
							<el-table-column prop="vin" label="VIN" width="180">
							</el-table-column>
							<el-table-column prop="estimatePrice" label="暂估价格" width="100">
							</el-table-column>
							<el-table-column prop="carSeries" label="车系名称" width="100">
							</el-table-column>
							<el-table-column prop="purchaseDate1" label="采购日期" width="100">
							</el-table-column>
							<el-table-column prop="purchaseNum" label="采购单号" width="100">
							</el-table-column>
							<el-table-column prop="carModelCode" label="车型代码" width="100">
							</el-table-column>
							<el-table-column prop="modelName" label="车型名称" width="100">
							</el-table-column>
							<el-table-column prop="configureCode" label="配置代码" width="100">
							</el-table-column>
							<el-table-column prop="configureName" label="配置名称" width="100">
							</el-table-column>
							<el-table-column prop="carModelYear" label="车型年" width="100">
							</el-table-column>
							<el-table-column prop="appearanceCode" label="外观代码" width="100">
							</el-table-column>
							<el-table-column prop="appearanceName" label="外观颜色" width="100">
							</el-table-column>
							<el-table-column prop="trimCode" label="内饰代码" width="100">
							</el-table-column>
							<el-table-column prop="trimName" label="内饰名称" width="100">
							</el-table-column>
							<el-table-column prop="chooseCode" label="加装代码" width="100">
							</el-table-column>
							<el-table-column prop="chooseName" label="加装名称" width="100">
							</el-table-column>
							<el-table-column prop="distributionDate" label="配货日期" width="100">
							</el-table-column>
							<el-table-column prop="sendDate" label="发货日期" width="100">
							</el-table-column>
							<el-table-column prop="oldNum" label="提单号" width="100">
							</el-table-column>
							<el-table-column prop="distributionStatus" label="配货状态" width="100">
							</el-table-column>
							<el-table-column prop="provideCompanyName" label="供货单位" width="100">
							</el-table-column>
						</el-table>
						<el-pagination small @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="CurentPage" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="tableData.total">
						</el-pagination>
					</el-col>
				</el-row>
			</el-tab-pane>
		</el-tabs>
		<carserice :show="showStart" v-if="showStart" v-on:close="showStart=false" v-on:insert="insert"></carserice>
		<!-- 弹出部门选择树-->
		<el-dialog title="选择公司" v-model="deptShow" size="small">
			<el-tree v-if="deptShow" :data="deptTreeData" ref="resTree" show-checkbox node-key="id" :highlight-current=true :props="defaultProps" accordion :default-checked-keys="checkedResKeys" :filter-node-method="filterNode"></el-tree>

			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="deptShow = false">关 闭</el-button>
				<el-button type="primary" @click="saveRes">提 交</el-button>
			</div>
		</el-dialog>
		<el-dialog title="暂估价格" v-model="editFormShow" size="tiny">
			<el-form :model="comFormDataPrice" label-width="100px">
				<el-col :span="24">
					<el-form-item label="车辆金额：" prop="price">
						<el-input size="small" v-model="comFormDataPrice.price"></el-input>
					</el-form-item>
				</el-col>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="editFormShow = false">取 消</el-button>
				<el-button type="primary" v-on:click='saveEditPrice'>提 交</el-button>
			</div>
		</el-dialog>
		<!--
        	作者：1813180149@qq.com
        	时间：2017-06-04
        	描述：添加车辆
        -->
		<el-dialog title="添加车辆" v-model="addNoStoreFormShow" size="small">
			<el-row>
				<el-card class="box-cardaasCar">
					<el-col :span="2" style="">
						<p class="queryLabel">查找车辆:</p>
					</el-col>
					<el-col :span="8">
						<el-input placeholder="请输入VIN" size="small" v-model="addVIN">
						</el-input>
					</el-col>
					<el-col :span="8" :offset="2">
						<el-button @click="findCar" type="info">查找车辆</el-button>
					</el-col>
				</el-card>
			</el-row>
			<el-row>
				<el-card class="box-cardaas">
					<el-form :model="addNoStoreFormData" ref="addNoStoreForm" :rules="addNoStoreRule" label-width="100px">
						<el-col :span="11" style="margin-right:20px;">
							<el-form-item label="车系" required prop="carSeries">
								<el-input placeholder="请选择车系" size="small" icon="search" v-model="carModelCodes" :on-icon-click="handleIconClick">
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:20px;">
							<el-form-item label="车辆型号" required prop="carModelId">
								<el-select size="small" style="width: 100%;" v-model="addNoStoreFormData.carModelId" placeholder="请选择配置" clearable @change="changeModels">
									<el-option v-for="item in modelCombos" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:20px;">
							<el-form-item label="车辆配置" required prop="configureId">
								<el-select size="small" style="width: 100%;" v-model="addNoStoreFormData.configureId" placeholder="请选择配置" clearable>
									<el-option v-for="item in configCombos" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:20px;">
							<el-form-item label="车型年" prop="carModelYear">
								<el-input size="small" v-model="addNoStoreFormData.carModelYear"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:20px;">
							<el-form-item label="外观" prop="appearanceCode">
								<el-select size="small" style="width: 100%;" v-model="addNoStoreFormData.appearanceCode" placeholder="请选择外观" clearable>
									<el-option v-for="item in appearanceCombos" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:20px;">
							<el-form-item label="内饰" prop="trimCode">
								<el-select size="small" style="width: 100%;" v-model="addNoStoreFormData.trimCode" placeholder="请选择外观" clearable>
									<el-option v-for="item in interiorCombos" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:20px;">
							<el-form-item label="加装信息" prop="chooseName">
								<el-input size="small" v-model="addNoStoreFormData.chooseName"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:20px;">
							<el-form-item label="VIN" required prop="vin">
								<el-input size="small" v-model="addNoStoreFormData.vin"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:20px;">
							<el-form-item label="发动机号" prop="engineNum">
								<el-input size="small" v-model="addNoStoreFormData.engineNum"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:20px;">
							<el-form-item label="合格证号" prop="certificateNum">
								<el-input size="small" v-model="addNoStoreFormData.certificateNum"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:15px;">
							<el-form-item label="暂估成本" prop="estimatePrice">
								<el-input size="small" v-model="addNoStoreFormData.estimatePrice"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:15px;">
							<el-form-item label="采购单号" prop="purchaseNum">
								<el-input size="small" v-model="addNoStoreFormData.purchaseNum"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:15px;">
							<el-form-item label="采购日期" prop="purchaseDate">
								<el-date-picker v-model="addNoStoreFormData.purchaseDate" size="small" style="width:100%;" type="date" clearable placeholder="配货日期">
								</el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:15px;">
							<el-form-item label="配货日期" prop="distributionDate">
								<el-date-picker v-model="addNoStoreFormData.distributionDate" size="small" style="width:100%;" type="date" clearable placeholder="配货日期">
								</el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:15px;">
							<el-form-item label="发货日期" prop="sendDate">
								<el-date-picker v-model="addNoStoreFormData.sendDate" size="small" style="width:100%;" type="date" clearable placeholder="配货日期">
								</el-date-picker>
							</el-form-item>
						</el-col>

						<el-col :span="11" style="margin-right:15px;">
							<el-form-item label="提单号" prop="oldNum">
								<el-input size="small" v-model="addNoStoreFormData.oldNum"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:15px;">
							<el-form-item label="配货状态" prop="distributionStatus">
								<el-input size="small" v-model="addNoStoreFormData.distributionStatus"></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="11" style="margin-right:15px;">
							<el-form-item label="供货单位" prop="provideCompanyName">
								<el-select size="small" style="width: 100%;" v-model="addNoStoreFormData.provideCompanyName" placeholder="请选择供货单位" clearable>
									<el-option v-for="item in customerCombos" :label="item.customerNick" :value="item.customerNick"></el-option>
								</el-select>
								<!--<el-input size="small" v-model="addNoStoreFormData.provideCompanyName"></el-input>-->
							</el-form-item>
						</el-col>

					</el-form>
				</el-card>
			</el-row>
			<div slot="footer" class="dialog-footer">
				<el-button @click="addNoStoreFormShow = false">取 消</el-button>
				<el-button type="primary" @click="saveNoStore">提 交</el-button>
			</div>
		</el-dialog>

	</div>
</template>

<script>
	import moment from 'moment'
	import carserice from '../../insPlugins/carSeries.vue'
	export default {
		data: function() {
			return {
				//历史车辆标识
				addflog:false,
				//查询历史车辆的VIN
				addVIN: "",
				carSaleStatus: [],
				//新增表单数据
				addNoStoreFormData: {
					carSeriesId: "", //车系
					carModelId: "", //车型
					configureId: "", //配置
					appearanceCode: "", //外观
					trimCode: "", //内饰
					carModelYear: "", //车型年
					chooseName: "", //加装信息
					vin: "",
					engineNum: "", //发动机号
					certificateNum: "", //合格证号
					estimatePrice: "", //暂估成本
					carSaleStatus: "",
					purchaseNum: "", //采购单号
					purchaseDate: "", //采购日期
					distributionDate: "", //配货日期
					sendDate: "", //发货日期
					oldNum: "", //提单号
					distributionStatus: "", //配货状态
					provideCompanyName: "", //货源

				},
				//初始化新增表单数据
				addNoStoreEmptyData: {
					carSeriesId: "", //车系
					carModelId: "", //车型
					configureId: "", //配置
					appearanceCode: "", //外观
					trimCode: "", //内饰
					carModelYear: "", //车型年
					chooseName: "", //加装信息
					vin: "",
					engineNum: "", //发动机号
					certificateNum: "", //合格证号
					estimatePrice: "", //暂估成本
					carSaleStatus: "",
					purchaseNum: "", //采购单号
					purchaseDate: "", //采购日期
					distributionDate: "", //配货日期
					sendDate: "", //发货日期
					oldNum: "", //提单号
					distributionStatus: "", //配货状态
					provideCompanyName: "", //货源
				},
				addNoStoreFormShow: false,
				//新增车辆的显示
				addFormShow: false,
				//所有的组织机构树
				allTreeNode: [],
				//供货单位的下拉
				customerCombos: [],
				//树型数据
				deptTreeData: [],
				//部门树
				defaultProps: {
					children: 'child',
					label: 'oName'
				},
				//默认选择中
				checkedResKeys: [],
				//显示单位
				deptShow: false,
				//tab默认显示
				activeName: 'first',
				//暂估金额显示框
				editFormShow: false,
				//修改金额的form
				comFormDataPrice: {
					id: "",
					price: ""
				},
				//车系选择窗
				showStart: false,
				//查询条件-车型
				carModel: "",
				//日期
				data: {
					firstStart: "",
					firstStarts: ""
				},
				//页码数
				CurentPage: 1,
				//每页的数量
				page: this.page,
				tableData: {
					total: 0,
					dataList: []
				},
				carStart: "",
				carStartComboData: [{
					value: '0',
					label: '采购在途'
				}, {
					value: '1',
					label: '在库'
				}, {
					value: '2',
					label: '已售'
				}, {
					value: '3',
					label: '调拨在途'
				}],
				//选中的列
				multipleSelection: [],
				//查询条件
				carSelect: {
					//车辆状态 
					status: "",
					//单位 
					companyId: [],
					//初次入库起
					purchaseStartDate: "",
					//初次入库止 
					purchaseStopDate: "",
					//车系代码
					carSeriesCode: "",
					//车型代码 
					carModelCode: "",
					//配置代码
					carConfigureCode: "",
					//仓库
					warehouse: "",
					//vin
					vin: ""
				},
				//查询条件清空
				carSelectS: {
					//车辆状态 
					status: "",
					//单位 
					companyId: [],
					//初次入库起
					purchaseStartDate: "",
					//初次入库止 
					purchaseStopDate: "",
					//车系代码
					carSeriesCode: "",
					//车型代码 
					carModelCode: "",
					//配置代码
					carConfigureCode: "",
					//仓库
					warehouse: "",
					//vin
					vin: ""
				},
				loadingVue: null,
				//车型名称
				carModelCode: "",
				//配置的下拉
				configCombo: [],
				//车型的下拉
				modelCombo: [],

				//车型名称
				carModelCodes: "",
				//配置的下拉
				configCombos: [],
				//车型的下拉
				modelCombos: [],

				//外观的下拉
				appearanceCombos: [],
				//内饰的下拉
				interiorCombos: [],

				//单位名称
				carSelectCompany: "",
				//查询的类型
				queryStatus: "0",
				addNoStoreRule: {
					carSeriesId: [{
						required: true,
						message: '请选择车系',
						trigger: 'change'
					}],
					carModelId: [{
						required: true,
						message: '请选择车型',
						trigger: 'blur'
					}],
					configureId: [{
						required: true,
						message: '请选择配置',
						trigger: 'blur'
					}],
					vin: [{
						required: true,
						message: '请输入vin',
						trigger: 'blur'
					}],

				},
			}
		},
		methods: {
			//查找历史车辆
			findCar: function() {
				this.$http.get(this.API_ROOT + '/scm/car/queryByVin', {
					params: {
						vin: this.$data.addVIN
					}
				}).then(resp => {
					if(resp.data.success) {
						this.$data.addflog=true;
						this.$data.addNoStoreFormData = resp.data.data[0];
						this.insert(resp.data.data[0].carSeriesId,resp.data.data[0].carSeries);
						this.$message({
							message: "请核对车辆信息无误再提交！",
							type: 'warning'
						});
					} else {
						this.$message.error(resp.data.msg);
					}
				}, resp => {});
			},
			//非本店入库时保存车辆信息
			saveNoStore: function(index) {
				debugger;
				this.$refs.addNoStoreForm.validate(function(valid) {
					if(valid) {
						this.$data.addNoStoreFormData.purchaseDate = this.momentFu(this.$data.addNoStoreFormData.purchaseDate);
						this.$data.addNoStoreFormData.distributionDate = this.momentFu(this.$data.addNoStoreFormData.distributionDate);
						this.$data.addNoStoreFormData.sendDate = this.momentFu(this.$data.addNoStoreFormData.sendDate);
						this.$http.post(this.API_ROOT + '/scm/car/save', this.$data.addNoStoreFormData)
							.then(resp => {
								if(resp.data.success) {
									this.$message(resp.data.msg);
									this.$data.addNoStoreFormShow = false;
									this.query();
								} else {
									this.$message.error(resp.data.msg);
								}
							}, resp => {});
					}
					return false;
				}.bind(this));
			},
			//新增车辆
			add: function() {
				this.$data.carModelCodes="";
				this.$data.addNoStoreFormData = Object.assign(this.$data.addNoStoreFormData, this.$data.addNoStoreEmptyData)
				this.$data.addNoStoreFormShow = true;
				this.$data.addflog=false;
			},
			//修改车辆
			edit: function() {
				if(this.$data.multipleSelection.length < 1) {
					this.$message.error("请选择车辆");
				} else {
					this.$data.addNoStoreFormData = Object.assign(this.$data.addNoStoreFormData, this.$data.addNoStoreEmptyData)
					this.$data.addNoStoreFormShow = true;
				}
			},

			//保存查询树
			saveRes: function() {
				debugger;
				this.$data.carSelect.companyId = this.$refs.resTree.getCheckedKeys();
				var check = new Array();
				check = this.$refs.resTree.getCheckedNodes();
				for(var i = 0; i < check.length; i++) {
					this.$data.carSelectCompany += check[i].oName + "||"
				};
				debugger;
				this.$data.deptShow = false;
			},
			filterNode: function(value, data, node) {
				if(!value) return true;
				return data.resName.indexOf(value) !== -1;
			},
			//打开部门
			openDeptTree: function(e) {
				this.$data.deptShow = true;
			},
			handleClick(tab, event) {
				//先清空查询条件
				//this.clean();
				debugger;
				if(tab.name == "first") {
					this.$data.queryStatus = "0"
				} else {
					this.$data.queryStatus = "3"
				}
				this.$data.CurentPage = 1
				this.query();
			},
			//清空查询条件
			clean: function() {
				this.$data.data.firstStart = "";
				this.$data.data.firstStarts = "";
				this.$data.carSelect = Object.assign(this.$data.carSelect, this.$data.carSelectS);
				this.$data.carModelCode = "";
				this.$data.carSelect.companyId = this.$data.allTreeNode;
				this.$data.carSelectCompany = "";
			},
			del: function() {
				if(this.$data.multipleSelection.length < 1) {
					this.$message.error("请选择车辆");
				} else {
					this.$confirm('确认要删除这些数据吗?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						var data = [];
						for(var i = 0; i < this.$data.multipleSelection.length; i++) {
							data[i] = this.$data.multipleSelection[i].vin
						}
						this.$http.post(this.API_ROOT + '/scm/car/delUserlessCar', data, {
							params: {}
						}).then((response) => {
							this.$message(response.data.msg);
							this.query();
						}, (response) => {});
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '已取消此操作'
						});
					});
				}
			},
			//车型改变的回调
			changeModel: function(val) {
				if(val != "") {
					this.comboConfigure(val);
				}
				debugger;
			},
			//车型改变的回调
			changeModels: function(val) {
				if(val != "") {
					this.comboConfigures(val);
				}
				debugger;
			},
			//刷新车型
			refreshC: function() {
				this.$data.loadingVue = this.$loading({
					fullscreen: false,
					text: "正在刷新数据，请稍候"
				});
				this.$http.post(this.API_ROOT + '/scm/car/flashModelId', {
					params: {}
				}).then((response) => {
					debugger;
					this.$data.loadingVue.close();
					this.$message(response.data.msg);
					this.query();
				}, (response) => {});
			},
			//刷新车型
			refreshP: function() {
				this.$data.loadingVue = this.$loading({
					fullscreen: false,
					text: "正在刷新数据，请稍候"
				});
				this.$http.post(this.API_ROOT + '/scm/car/refreshEstimatePrice', {
					params: {}
				}).then((response) => {
					debugger;
					this.$data.loadingVue.close();
					this.$message(response.data.msg);
					this.query();
				}, (response) => {});
			},
			//刷新配置
			refreshF: function() {
				//等待动画
				this.$data.loadingVue = this.$loading({
					fullscreen: false,
					text: "正在刷新数据，请稍候"
				});
				this.$http.post(this.API_ROOT + '/scm/car/flashConfigId', {
					params: {}
				}).then((response) => {
					debugger;
					this.$data.loadingVue.close();
					this.$message("保存成功");
					this.query();
				}, (response) => {});
			},
			//刷新
			refreshW: function() {
				//等待动画
				this.$data.loadingVue = this.$loading({
					fullscreen: false,
					text: "正在刷新数据，请稍候"
				});
				this.$http.post(this.API_ROOT + '/scm/car/refershCarAppearanceAndInterior', {
					params: {}
				}).then((response) => {
					debugger;
					this.$data.loadingVue.close();
					this.$message("保存成功");
					this.query();
				}, (response) => {});
			},
			//根据内容改变表格颜色（无车型红色，无配置蓝色）
			tableRowClassNames(row, index) {
				//debugger;
				if(row.modelName == "" || row.modelName == null) {
					return 'noSer-rows';
				} else if(row.configureName == "" || row.configureName == null) {
					return 'noPri-rows';
				} else {
					return "";
				}
			},
			//保存金额
			saveEditPrice: function() {
				debugger;
				this.$http.get(this.API_ROOT + '/scm/car/updateEstimate', {
					params: {
						id: this.$data.comFormDataPrice.id,
						price: this.$data.comFormDataPrice.price
					}
				}).then((response) => {
					debugger;
					this.$message("保存成功");
					this.query();
				}, (response) => {});
				this.$data.editFormShow = false;
			},
			//维护暂估价
			editPrice: function(index) {
				debugger;
				if(this.$data.multipleSelection.length == 1) {
					this.$data.comFormDataPrice.id = this.$data.multipleSelection[0].id;
					this.$data.comFormDataPrice.price = "";
					this.$data.editFormShow = true;
				} else {
					this.$message.error("请选择一辆车！");
				}
			},
			//车系选择的回调
			insert: function(val, lable) {
				debugger;
				//新增车辆车系选择回调
				if(this.$data.addNoStoreFormShow == true) {
					debugger;
					this.$data.addNoStoreFormData.carSeriesId = val;
					this.$data.carModelCodes = lable;
					this.getAppearanceCombo(val);//外观
					this.getInteriorCombo(val);//内饰
					this.$http.get(this.API_ROOT + '/base/carModel/combo', {
						params: {
							seriesId: val
						}
					}).then((response) => {
						debugger;
						this.$data.modelCombos = response.data;
						if(!this.$data.addflog){
						this.$data.addNoStoreFormData.carModelCode = "";
						this.$data.addNoStoreFormData.carConfigureCode = "";
						}
						//this.$message(response.data);
					}, (response) => {});
				} else { //查询条件的选择车系回调
					this.$data.carSelect.carSeriesCode = val;
					this.$data.carModelCode = lable;
					this.$http.get(this.API_ROOT + '/base/carModel/combo', {
						params: {
							seriesId: val
						}
					}).then((response) => {
						debugger;
						this.$data.modelCombo = response.data;
						this.$data.carSelect.carModelCode = "";
						this.$data.carSelect.carConfigureCode = "";
						//this.$message(response.data);
					}, (response) => {});
				}
			},
			//查询外观
			getAppearanceCombo: function(val) {
				this.$http.get(this.API_ROOT + '/scm/appearance/combo', {
					params: {
						carSeriesId: val
					}
				}).then((response) => {
					debugger;
					this.$data.appearanceCombos = response.data;
					//this.$message(response.data);
				}, (response) => {});
			},
			//查询内饰
			getInteriorCombo: function(val) {
				this.$http.get(this.API_ROOT + '/scm/interior/combo', {
					params: {
						seriesId: val
					}
				}).then((response) => {
					debugger;
					this.$data.interiorCombos = response.data;
					//this.$message(response.data);
				}, (response) => {});
			},
			//获取供货单位
			getCustomerCombo: function() {
				this.$http.get(this.API_ROOT + '/scm/provideCompany/combo', {
					params: {
						type: "0"
					}
				}).then((response) => {
					debugger;
					this.$data.customerCombos = response.data;
					//this.$message(response.data);
				}, (response) => {});
			},
			//选择车型后的回调
			comboConfigure: function(val) {
				this.$http.get(this.API_ROOT + '/base/carConfigure/combo', {
					params: {
						modelId: val
					}
				}).then((response) => {
					debugger;
					this.$data.configCombo = response.data;
					
					this.$data.carSelect.carConfigureCode = "";
					
					//this.$message(response.data);
				}, (response) => {});
			},
			//选择车型后的回调
			comboConfigures: function(val) {
				this.$http.get(this.API_ROOT + '/base/carConfigure/combo', {
					params: {
						modelId: val
					}
				}).then((response) => {
					debugger;
					this.$data.configCombos = response.data;
					if(!this.$data.addflog){
					this.$data.addNoStoreFormData.configureId = "";
					}
					//this.$message(response.data);
				}, (response) => {});
			},
			//打开车型车系选择
			handleIconClick: function() {
				this.$data.showStart = true;
			},
			//复选框回调函数
			handleSelectionChange: function(val) {
				debugger;
				this.$data.multipleSelection = val;
			},
			//列表，分页大小切换
			handleSizeChange: function() {},
			//列表,当前页切换
			handleCurrentChange: function(currentPage) {
				this.$data.CurentPage = currentPage;
				this.query();
			},
			//查询
			query: function() {
				this.$data.carSelect.purchaseStartDate = this.momentFu(this.$data.data.firstStart);
				this.$data.carSelect.purchaseStopDate = this.momentFu(this.$data.data.firstStarts);
				this.$http.post(this.API_ROOT + '/scm/car/newPage', this.$data.carSelect, {
					params: {
						root: window.localStorage.getItem("companyId"),
						status: this.$data.queryStatus,
						start: this.$data.CurentPage,
						limit: this.$data.page.pageSize
					}
				}).then(resp => {
					if(resp.data.success) {
						resp.data.total = parseInt(resp.data.total);
						this.$data.tableData = resp.data;
					} else {
						this.$message.error(resp.data.msg);
					}
				}, resp => {})
				debugger;
			},
			//时间判断为空的封装
			momentFu: function(dt) {
				if(dt == '' || dt == null || dt == undefined) {
					return "";
				} else {
					return this.moment(dt).format("YYYY-MM-DD");
				}
			},
			//状态转换
			statusCov: function(row, column) {
				switch(row.status) {
					case "0":
						return "采购在途";
						break;
					case "1":
						return "在库";
						break;
					case "2":
						return "已售";
						break;
					case "3":
						return "调拨在途";
						break;
					default:
						return "调拨在途";
				}
			},
			//获取组织机构树的所有节点
			getTreeNode: function(treeAll) {
				debugger;
				for(var i = 0; i < treeAll.length; i++) {
					this.$data.allTreeNode.push(treeAll[i].id);
					if(treeAll[i].child.lenth == 0) {
						return;
					} else {
						this.getTreeNode(treeAll[i].child);
					}
				}
			},
			//时间判断为空的封装
			momentFu: function(dt) {
				if(dt == '' || dt == null || dt == undefined) {
					return "";
				} else {
					return this.moment(dt).format("YYYY-MM-DD");
				}
			},
		},
		components: {
			carserice
		},
		created: function() {
			//获取供货单位
			this.getCustomerCombo();
			//给单位默认值
			this.$data.carSelectCompany = window.localStorage.getItem("companyName");
			this.$data.carSelect.companyId = window.localStorage.getItem("companyId");
			//获取部门资源树
			this.$http.get(this.API_ROOT + '/rbac/dept/tree', {
				params: {
					root: window.localStorage.getItem("companyId"),
					type: "1",
				}
			}).then((response) => {
				this.$data.deptTreeData = response.data.dataList;
				this.$data.allTreeNode = [];
				this.getTreeNode(this.$data.deptTreeData);
				this.$data.carSelect.companyId = this.$data.allTreeNode
				this.query();
			}, (response) => {});
			//车辆销售状态
			this.$http.get(this.API_ROOT + '/base/dict/combo', {
				params: {
					group: "scmWarehouseCarSaleStatus"
				}
			}).then((response) => {
				this.$data.carSaleStatus = response.data;
			}, (response) => {});
		}
	}
</script>
<style>
	.el-table .noPri-rows {
		background: #FFCC66;
	}
	
	.el-table .noSer-rows {
		background: #FFFF66
	}
	
	.box-cardaas {
		width: 100%;
		height: 550px;
		margin-top: 20px;
		margin-bottom: 20px;
	}
	
	.box-cardaasCar {
		width: 100%;
		height: 70px;
		margin-top: 20px;
		margin-bottom: 0px;
	}
</style>